package com.example.persistence;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;

import com.example.R;

public class MyApplication extends Application {
	private String deviceId;
	private String phoneNumber;
	private String packageName;
	private String versionName;
	private int versionCode;
	private String appName;
	private int deviceWidth, deviceHeight;
	
	@Override
	public void onCreate() {
		super.onCreate();
        
		DisplayMetrics displayMetrics = new DisplayMetrics();
		((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics);
		deviceWidth = displayMetrics.widthPixels;
		deviceHeight = displayMetrics.heightPixels;
		
		TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
		deviceId = telephonyManager.getDeviceId();
		phoneNumber = telephonyManager.getLine1Number();
		appName = getString(R.string.app_name);
		packageName = getPackageName();
		try {
			PackageInfo packageInfo = getPackageManager().getPackageInfo(packageName, 0);
			versionName = packageInfo.versionName;
			versionCode = packageInfo.versionCode;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		Log.i("MyApplication onCreate", "deviceId=" + deviceId + " phoneNumber=" + phoneNumber);
		Log.i("MyApplication onCreate", "deviceWidth=" + deviceWidth + " deviceHeight=" + deviceHeight);
		Log.i("MyApplication onCreate", "appName=" + appName + " packageName=" + packageName);
		Log.i("MyApplication onCreate", "versionName=" + versionName + " versionName=" + versionName);
	}

	public int getSdkVersion() {
		return Build.VERSION.SDK_INT;
	}
	public String getSdkVersionString() {
		return Build.VERSION.SDK;
	}
	public String getAppId() {
		return packageName;
	}
	public String getDeviceId() {
		return deviceId;
	}
	public String getPhoneNumber() {
		return phoneNumber;
	}
	public String getVersionName() {
		return versionName;
	}
	public int getVersionCode() {
		return versionCode;
	}
	public String getAppName() {
		return appName;
	}
	public int getDeviceWidth() {
		return deviceWidth;
	}
	public int getDeviceHeight() {
		return deviceHeight;
	}
}
